using CodePlex.TfsLibrary.ObjectModel;

namespace CodePlex.CodePlexClientLibrary
{
    [Command("list", "Lists items in a directory on the server", AltName = "dir", MinArgs = 1, MaxArgs = 1, UsageSummary = "<project>[:/path] [options]",
        UsageDescription = @"In verbose mode:
  The first column is the change set ID
  The second column is the item ID
  The third column is the modification date/time
  The fourth column is the item size
  The fifth column is the item name")]
    public class ListCommand_CodePlex : ListCommand
    {
        readonly ICodePlexProjectInfoService projectInfoService;

        public ListCommand_CodePlex(ICodePlexProjectInfoService projectInfoService)
        {
            this.projectInfoService = projectInfoService;
        }

        protected override void GetListParameters(out string tfsUrl,
                                                  out string serverPath)
        {
            string projectName;
            string projectPath;

            CodePlexClientUtil.ParseProjectName(Arguments[0], out projectName, out projectPath);

            CodePlexTfsProjectInfo info = projectInfoService.GetTfsInfoForProject(projectName);

            tfsUrl = info.TfsUrl;
            serverPath = TfsUtil.CombineProjectPath(info.ServerPath, projectPath.TrimStart('/'));
        }
    }
}